/**
 * @Author：ming
 * @Date：2023/10/27 11:29 PM
 * @Filename：Hot200
 */

/**
 * @author ming
 */
public class Hot200 {
    public int numIslands(char[][] grid) {
        int count  =0;
        for (int i = 0; i < grid.length; i++) {
            for (int j = 0; j < grid[0].length; j++) {
                if(getArea(grid,i,j)>0){
                    count ++;
                }
            }
        }
        return count;

    }
    public static  int getArea(char[][] grid,int r,int c){
        if(!inFind(grid,r,c)){
            return 0;
        }
        if(grid[r][c]=='0'){
            return 0;
        }

        if(grid[r][c]=='2'){
            return 0;
        }

        grid[r][c]='2';

        return 1
                +getArea(grid,r,c-1)
                +getArea(grid,r,c+1)
                +getArea(grid,r-1,c)
                +getArea(grid,r+1,c);
    }
    //坐标在范围内
    public static boolean inFind(char[][] grid,int r ,int c){
        return r>=0&&r<grid.length
                &&
                c>=0&&c<grid[0].length;
    }
}
